第一次的jQuery以熟悉jQuery寫法和簡單的事件(click,toggle)

確保jQuery有載入到網頁

$(document).ready(function() {

});

熟悉語法

$(document).ready(function() {
    $('h1').hide(); //將h1隱藏
    $('h1').show(); //將h1顯示
    $(".title").hide(); //將class名稱為title隱藏
    $("h3 .header").hide(); //將h3裡的header隱藏
});

click()事件演練

$(document).ready(function() {
    $(".button").click(function() {
        $("h1").hide();
    }); //點選按鈕將h1隱藏
});


toggle()事件演練

toggle()判斷現在為顯示或隱藏,若為顯示,則點選按鈕將h1隱藏,反之

$(document).ready(function() {
    $(".button").click(function() {
        $("h1").toggle();
    }); 
});

jQuery字典:oscarotero.com/jquery/

#jquery #前端







你可能感興趣的文章

React-[useEffect篇]- Cleanup函式

React-[useEffect篇]- Cleanup函式

JS 與瀏覽器的溝通與網頁事件處理

JS 與瀏覽器的溝通與網頁事件處理

筆記、[JS102] 升級你的 JavaScript 技能:ES6 + npm + Jest

筆記、[JS102] 升級你的 JavaScript 技能:ES6 + npm + Jest






留言討論